//
// Created by root on 25-5-27.
//
#pragma once
#include "extra_command.h"
#include "ReadOP2.h"
#include "ConvertRst.h"
using namespace std;


int main(int argc, char* argv[]){

    cout << "test" <<endl;
    string exeName = argv[0];
    GeneralMethod::replaceSplash(exeName);
    std::string exe_directory = exeName.substr(0, exeName.find_last_of("/"));

    string sys_path_str = exe_directory;	sys_path_str += ":";
    sys_path_str += (exe_directory + "/lib:");
    sys_path_str += (exe_directory + "/lib/python3.12/site-packages:");
    sys_path_str += (exe_directory + "/lib/python3.12/lib-dynload:");
    sys_path_str += (exe_directory + "/lib/python3.12:");
    // wchar_t* test = GeneralMethod::char_to_wchar(sys_path_str.c_str());
    // Py_SetPath(test);
    // const char* version = Py_GetVersion();
    // std::cout << "Python版本: " << version << std::endl;
    string home = exe_directory;
    wchar_t* home_wchar = GeneralMethod::char_to_wchar(home.c_str());
    Py_SetPythonHome(home_wchar);
    // Py_Initialize();
    // PyRun_SimpleString("from ansys.mapdl import reader");
    // PyRun_SimpleString("print(dir(reader))");
    vector<string> para_list;
    for (int i = 1; i < argc; ++i) {
        string temp = argv[i];
        GeneralMethod::replaceSplash(temp);
        //cout << "para_list"<<temp<<endl;
        para_list.emplace_back(temp);
    }
    string read_path = para_list[0];
    string file_name = para_list[1];
    string save_path = para_list[2];
    string upper_filename = file_name;
    GeneralMethod::to_upper(upper_filename);
    string suffix = upper_filename.substr(upper_filename.find_last_of("."));
    if (suffix==".OP2") {
        sys_path_str += (exe_directory + "/lib/python3.12/site-packages-for-pynastran:");
        sys_path_str += (exe_directory + "/lib/python3.12/site-packages-for-meshio:");
        wchar_t* test = GeneralMethod::char_to_wchar(sys_path_str.c_str());
        Py_SetPath(test);
        ReadOP2::getInstance().setInputFile(read_path + "/" + file_name);
        ReadOP2::getInstance().setOutputDir(save_path);
        ReadOP2::getInstance().setExeFilePath(exe_directory);

        ReadOP2::getInstance().writeMSHFile();
        //ReadOP2::getInstance().writeVTKFile();

    }
    else if (suffix==".RST") {
        sys_path_str += (exe_directory + "/lib/python3.12/site-packages-for-ansys:");
        sys_path_str += (exe_directory + "/lib/python3.12/site-packages-for-meshio:");
        wchar_t* test = GeneralMethod::char_to_wchar(sys_path_str.c_str());
        Py_SetPath(test);
        ConvertRst::ConvertRstToFile(read_path + "/" + file_name, save_path, 1);
    }


    return 1;
}



